package com.jmyd.sharding.server.domain.vo;

import com.jmyd.sharding.server.domain.po.TAddress;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author samphin
 * @date 2021/8/5 10:05
 */
@Data
public class AddressVo implements Serializable {

    private Long id;

    /**
     * 编码
     */
    private String code;

    /**
     * 名称
     */
    private String name;

    /**
     * 父id
     */
    private String pid;

    /**
     * 1国家2省3市4县区
     */
    private Integer type;

    private Integer lit;

    public AddressVo build(TAddress po) {
        BeanUtils.copyProperties(po, this);
        this.setId(po.getId());
        return this;
    }

    public List<AddressVo> build(List<TAddress> poList) {
        if (CollectionUtils.isEmpty(poList)) {
            return new ArrayList<>(1);
        }
        return poList.stream().map(po -> new AddressVo().build(po)).collect(Collectors.toList());
    }
}